package com.topvision.utils.web;

import org.springframework.http.HttpStatus;

import javax.servlet.http.HttpServletRequest;


/**
 * @author shengwm
 * @version V0.0.1
 * @Title: WebUtil
 * @Package com.seed.common.utils.web
 * @Description: TODO
 * @date 2017/3/24 10:15
 */
public class WebUtil {
    private static final String XML_HTTP_REQUEST = "XMLHttpRequest";
    private static final String X_REQUESTED_WITH = "X-Requested-With";

    private static final String CONTENT_TYPE = "Content-type";
    private static final String CONTENT_TYPE_JSON = "application/json";

    public static boolean isAjax(HttpServletRequest request) {
        return XML_HTTP_REQUEST.equals(request.getHeader(X_REQUESTED_WITH));
    }

    public static boolean isError(HttpStatus status) {
        HttpStatus.Series series = status.series();
        return (HttpStatus.Series.CLIENT_ERROR.equals(series)
                || HttpStatus.Series.SERVER_ERROR.equals(series));
    }
}
